/*
 * @title: 登录调用后端api
 * @author: andy.ten@tom.com & xukaixing@hotmail.com
 * @Date: 2022-03-21 16:51:22
 * @LastEditors: andy.ten@tom.com
 * @LastEditTime: 2022-06-05 17:18:02
 * @version: 1.0.3
 * @copyright: copyright (c) 2022 andyten
 *  node: you can not copy and/or use and/or modify this program free,
 *  please reserve the segment above.Please mail me if you have any question.
 */
import fetch from '@/utils/ht.fetch';
import server from '@/api/ht.server';
import AppConfig from '@/appconfig';

// 注意： get 使用`params : {}`， 'PUT'、'POST'、'PATCH' 使用 `data : {}`
// 使用data相当于server端用对象接收参数，使用params相当于问号传参方式？a=1&b=2
// export const login = (username, password, code, uuid) => {
//   return request({
//     url: 'auth/login',
//     method: 'post',
//     data: {
//       username,
//       password,
//       code,
//       uuid
//     }
//   });
// };
export const login = (data) => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = AppConfig.gateWayUrl;
  return fetch.post(`${server.gateway_logins}/loginAuth/login`, data);
};

export const getGrantedMenus = (data) => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = AppConfig.gateWayUrl;
  return fetch.post(`${server.gateway_logins}/loginMenu/showGrantedMenus`, data);
};

export const getInfo = () => {
  return fetch.get({
    url: 'auth/info',
    method: 'get'
  });
};

export const getValidCodeImg = () => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = AppConfig.gateWayUrl;
  return fetch.get(`${server.gateway_logins}/loginAuth/loginVerifyCode`);
};

export function logout() {
  return fetch({
    url: 'auth/logout',
    method: 'delete'
  });
}
